<template>
	<view class="message">
		<view class="" style="height: 30px;" v-if="arrList.length != 0">
			<u-subsection :current="currentTrue" :list="arrList" @change="spanChange"></u-subsection>
		</view>
		<view class="" v-show="show">
			<plate-input :list="list" :fileds="['name']" @onSelect="lll">
			</plate-input>
		</view>
		<view class="" v-show="show1">
			<plate-input :list="list1" :fileds="['name']" @onSelect="lll1" :lHeight1="2">
			</plate-input>
		</view>
		<view class="" v-show="show2">
			<plate-input :list="list2" :fileds="['name']" @onSelect="lll2" :lHeight1="2">
			</plate-input>
		</view>
		<view class="" v-show="show3">
			<plate-input :list="list3" :fileds="['name']" @onSelect="lll3" :lHeight1="2">
			</plate-input>
		</view>
	</view>
</template>
<script>
	var listVal = []
	import plateInput from '@/pagesA/common/a-indexed-list/a-indexed-list.vue';
	import store from "@/store/index.js"
	export default {
		components: {
			plateInput
		},
		data() {
			return {
				list: [],
				list1:[],
				list2:[],
				list3:[],
				show:true,
				show1: false,
				show2: false,
				show3: false,
				content: '',
				clickTrue: '',
				objValue: '',
				objOne:'',
				
				arrList:[],
				currentTrue:null
				
			}
		},
		onLoad(option) {
			uni.showLoading({
				title: '加载中',
				mask: true,
				icon: 'loading',
			});
			var that = this
			this.objValue = option
			
			
			if (option.id == 1) {
				listVal = []
				this.$request('getInsCompanyList', {}, 'get', {}).then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.insCompanyName
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					this.list = listVal
					 uni.hideLoading();
				})
			} else if (option.id == 2) {
				listVal = []
				this.$request('getProvinceList', {}, 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.regionName
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					this.list = listVal
					 uni.hideLoading();
				})
			} else if (option.id == 3) {
				listVal = []
				this.$request('getCityListByProvinceCode', {
					regionCode: option.regionCode
				}, 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.regionName
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					this.list = listVal
					 uni.hideLoading();
				})
			}else if (option.id == 4) {
				listVal = []
				wx.setNavigationBarTitle({
					title: '品牌'
				})
				this.getDataTable(0)
				that.$request('getCarBrandList', 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.carBrandName
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					that.list = listVal
					 uni.hideLoading();
				})
			}else if (option.id == 5) {
				listVal = []
				that.show = false
				that.show1 = true
				wx.setNavigationBarTitle({
					title: '车系'
				})
					this.getDataTable(1)
				
				
				that.$request('getCarClassByBrand',{
					carBrand:option.regionCode
				}, 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.carClassName
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					that.list1 = listVal
					 uni.hideLoading();
				})
			}else if (option.id == 6) {
				wx.setNavigationBarTitle({
					title: '车型'
				})
				this.getDataTable(2)
				listVal = []
				that.show = false
				that.show1 = false
				that.show2 = true
				that.$request('getCarTypeByClass',{
					carClass:option.regionCode
				}, 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.carTypeName 
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					that.list2 = listVal
					 uni.hideLoading();
				})
			}else if (option.id == 7) {
				listVal = []
				wx.setNavigationBarTitle({
					title: '车型细分'
				})
				this.getDataTable(3)
				that.show = false
				that.show1 = false
				that.show2 = false
				that.show3 = true
				that.$request('getCarSubtypeByType',{
					carType:option.regionCode
				}, 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.carSubtypeName 
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					that.list3 = listVal
					 uni.hideLoading();
				})
			}


		},
		methods: {
			lll(item, index, cindex) {
				
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				uni.showLoading({
					title: '加载中',
					mask: true,
					icon: 'loading',
				});
				if (this.objValue.id == 2) {

					prevPage.$vm.userInfo.repairProvinceName = item.regionName;
					prevPage.$vm.userInfo.repairProvince = item.regionCode;
					prevPage.$vm.userInfo.regionCode = item.regionCode;
					prevPage.$vm.documentId = item.regionCode;
				} else if (this.objValue.id == 3) {
					prevPage.$vm.userInfo.repairCityName = item.regionName;
					prevPage.$vm.userInfo.repairCity = item.regionCode;

				} else if (this.objValue.id == 1) {
					prevPage.$vm.userInfo.insCompanyName = item.insCompanyName;
					prevPage.$vm.userInfo.insCompanyId = item.id;

				}else if (this.objValue.id == 4) {
					prevPage.$vm.userInfo.carBrandName = item.carBrandName;
					prevPage.$vm.userInfo.carBrand = item.carBrand;
					this.objOne = item
			
					this.arrList[0] = item
					this.currentTrue = 0
					
					this.show = false
					this.show1 = true
					listVal = []
					
					this.$request('getCarClassByBrand',{
						carBrand:item.carBrand
					}, 'get').then(res => {
						for (let item of Object.entries(res.data)) {
							var obj = {
								'letter': '',
								'data': []
							}
							item[1].data.forEach(i => {
								i.name = i.carClassName
							})
							obj.letter = item[0]
							obj.data = item[1].data
							listVal.push(obj)
						}
						this.list1 = listVal
						wx.setNavigationBarTitle({
							title: '车系'
						})
						 uni.hideLoading();
					})

				}else if (this.objValue.id == 5) {
					

				}else if (this.objValue.id == 6) {
					

				}else if (this.objValue.id == 7) {
					

				}


				// uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
				// 	delta: 1
				// });
			},
			lll1(item, index, cindex){
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				
				uni.showLoading({
					title: '加载中',
					mask: true,
					icon: 'loading',
				});
				prevPage.$vm.userInfo.carClassName = item.carClassName;
				prevPage.$vm.userInfo.carClass = item.carClass;
				this.objTwo = item
				// this.arrList 
				
				this.arrList[1] = item
				this.currentTrue = 1
				this.show = false
				this.show1 = false
				this.show2 = true
				listVal = []
				this.$request('getCarTypeByClass',{
					carClass:item.carClass
				}, 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.carTypeName 
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					this.list2 = listVal
					wx.setNavigationBarTitle({
						title: '车型'
					})
					 uni.hideLoading();
				})
			},
			lll2(item, index, cindex){
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				uni.showLoading({
					title: '加载中',
					mask: true,
					icon: 'loading',
				});
				prevPage.$vm.userInfo.carTypeName = item.carTypeName;
				prevPage.$vm.userInfo.carType = item.carType;
				this.objTwo = item
				// this.arrList 
				this.arrList[2] = item
				this.currentTrue = 2
				this.show = false
				this.show1 = false
				this.show2 = false
				this.show3 = true
				listVal = []
				this.$request('getCarSubtypeByType',{
					carType:item.carType
				}, 'get').then(res => {
					for (let item of Object.entries(res.data)) {
						var obj = {
							'letter': '',
							'data': []
						}
						item[1].data.forEach(i => {
							i.name = i.carSubtypeName 
						})
						obj.letter = item[0]
						obj.data = item[1].data
						listVal.push(obj)
					}
					this.list3 = listVal
					wx.setNavigationBarTitle({
						title: '车型细分'
					})
					 uni.hideLoading();
				})
			},
			lll3(item, index, cindex){
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				this.arrList[3] = item
				this.currentTrue = 3
				prevPage.$vm.userInfo.carSubtypeName = item.carSubtypeName;
				prevPage.$vm.userInfo.carSubtype = item.carSubtype;
				uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 1
				});
			},
			confirmTrue() {
				// B页面

				this.show = false
			},
			spanChange(e){
			
				this.currentTrue = e
				if(e == 0){
					this.show = true
					this.show1 = false
					this.show2 = false
					this.show3 = false
				}else if (e==1){
					this.show = false
					this.show1 = true
					this.show2 = false
					this.show3 = false
				}else if (e==2){
					this.show = false
					this.show1 = false
					this.show2 = true
					this.show3 = false
				}else if (e==3){
					this.show = false
					this.show1 = false
					this.show2 = false
					this.show3 = true
				}
			},
			getDataTable(i){
				let pages = getCurrentPages(); //获取所有页面栈实例列表
				let nowPage = pages[pages.length - 1]; //当前页页面实例
				let prevPage = pages[pages.length - 2]; //上一页页面实例
				// carBrandName: '',
				// carBrand: '',
				// carClassName: '',
				// carClass: '',
				// carTypeName: '',
				// carType: '',
				// carSubtypeName: '',
				// carSubtype: '',
				
				this.currentTrue = i
				
				if(prevPage.$vm.userInfo.carBrandName != ''){
					var obj = {
						name : prevPage.$vm.userInfo.carBrandName
					}
					this.arrList[0] =  obj
				}
				
				if(prevPage.$vm.userInfo.carClassName != ''){
					var obj = {
						name : prevPage.$vm.userInfo.carClassName
					}
					this.arrList[1] =  obj
				}
				if(prevPage.$vm.userInfo.carTypeName != ''){
					var obj = {
						name : prevPage.$vm.userInfo.carTypeName
					}
					this.arrList[2] =  obj
				}
				if(prevPage.$vm.userInfo.carSubtypeName != ''){
					var obj = {
						name : prevPage.$vm.userInfo.carSubtypeName
					}
					this.arrList[3] =  obj
				}
				
			}


		}
	}
</script>
